package cn.design;

import cn.design.realize.Flyweight;
import cn.design.realize.FlyweightFactory;

/**
 * @author dlq
 * @description 享元模式客户端
 * @date 2020/9/22 9:59
 * @since 1.0
 */
public class FlyweightClientDemo {

    public static void main(String[] args) {
        // 背景故事
        // 在 LOL英雄联盟中, 有几大类型的英雄，我们可以通过不同类型的英雄，选择具体英雄
        //在英雄池(享元池-缓存池)中划分出几种英雄
        //刺客
        Flyweight flyweight1 = FlyweightFactory.getFlyweight("刺客");
        //法师
        Flyweight flyweight2 = FlyweightFactory.getFlyweight("法师");
        //坦克
        Flyweight flyweight3 = FlyweightFactory.getFlyweight("坦克");
        //这里我再次划分一次 刺客,查看和上次划分的是否是一个对象
        Flyweight flyweight4 = FlyweightFactory.getFlyweight("刺客");
        System.out.println("flyweight1 == flyweight4: "+(flyweight1==flyweight4));
        System.out.printf("一共有%s种类型的英雄\n",FlyweightFactory.getTotal());
        //通过这几种类型选择具体英雄
        //刺客
        flyweight1.choiceLolHero("卡特琳娜");
        flyweight4.choiceLolHero("刀锋");
        //法师
        flyweight2.choiceLolHero("邪恶法师");
        flyweight2.choiceLolHero("机械先驱");
        //坦克
        flyweight3.choiceLolHero("盖伦");
        flyweight3.choiceLolHero("布隆");

        //在jdk原生的享元模式,就是冲缓存中获取  IntegerCache
        Integer i1 = Integer.valueOf(100);
        Integer i2 = Integer.valueOf(100);
        System.out.println(i1==i2);
        String s1 = "a";
        String s2 = "a";
        System.out.println(s1==s2);


    }
}
